cmake_minimum_required(VERSION 3.10)
set(CMAKE_CXX_STANDARD 17)
# add_compile_options(/gbk)
add_compile_options(/utf-8)
# add_compile_options(/GS- #禁用安全检查
#     /source-charset:utf-8 /execution-charset:gb2312
# )
project(MyAsioPro)

# aux_source_directory(. SRCS)
aux_source_directory(./sources SRCS)
include_directories(./includes)
# set(SRCS searchstr.cpp)
# set(LIBS ${CMAKE_CURRENT_SOURCE_DIR}/lib)
file(GLOB LIBS ${CMAKE_CURRENT_SOURCE_DIR}/lib/*.*)
# message(${LIBS})

# -------BOOST-------
# 设置Boost根目录
set(BOOST_ROOT D:/cppsoft/boost_1_85_0)
set(Boost_LIBRARY_DIRS D:/cppsoft/boost_1_85_0/lib)
# 查找Boost.Asio库
find_package(Boost 1.85.0 REQUIRED COMPONENTS)
# 头文件
link_directories(${Boost_LIBRARY_DIRS})
include_directories(${Boost_INCLUDE_DIRS})
message(Boost\ version: ${Boost_VERSION_STRING})
message(Boost\ include\ dir: ${Boost_INCLUDE_DIRS})
message(Boost\ library\ dir: ${Boost_LIBRARY_DIRS})
# 如果是MVSC 编译器，则添加_HAS_ITERATOR_DEBUGGING=0
# add_compile_definitions(_HAS_ITERATOR_DEBUGGING=0)
# 如果找不到Boost.Asio，则输出错误消息
if (Boost_FOUND)
    message(STATUS "Boost.Asio库已找到")
else()
    message(FATAL_ERROR "找不到Boost.Asio库，请确保安装了Boost并设置了正确的路径")
endif()

# -------MySQL-------
# set(mysql-concpp_DIR "D:/cppsoft/mysql-connector-c++-8.3.0-winx64")
# set(CMAKE_PREFIX_PATH "D:/cppsoft/mysql-connector-c++-8.3.0-winx64")
# set(MYSQL_CONCPP_ROOT "D:/cppsoft/mysql-connector-c++-8.3.0-winx64")
# set(MYSQL_CONCPP_LIBRARIES
#     ${MYSQL_CONCPP_ROOT}/lib64/vs14/mysqlcppconn.lib
#     ${MYSQL_CONCPP_ROOT}/lib64/vs14/mysqlcppconn8.lib
# )
# set(MYSQL_CONCPP_INCLUDE_DIRS "D:/cppsoft/mysql-connector-c++-8.3.0-winx64/include")
# # 包含 MySQL Connector/C++ 的头文件目录
# include_directories(${MYSQL_CONCPP_INCLUDE_DIRS})
# find_package(mysql-concpp REQUIRED)
# # 检查是否找到了 MySQL Connector/C++
# if(NOT MYSQL_CONCPP_FOUND)
# message(FATAL_ERROR "MySQL Connector/C++ not found. Please make sure it is installed and in your PATH.")
# endif()

set(MYSQL_CONCPP_ROOT "D:/cppsoft/mysql-connector-c++-8.0.31-winx64-debug/mysql-connector-c++-8.0.31-winx64")
set(Mysql_Concpp_Include "D:/cppsoft/mysql-connector-c++-8.0.31-winx64-debug/mysql-connector-c++-8.0.31-winx64/include")
include_directories(${Mysql_Concpp_Include})
# LINK_DIRECTORIES("D:/cppsoft/mysql-connector-c++-8.0.31-winx64-debug/mysql-connector-c++-8.0.31-winx64/lib64/debug")
set(MYSQL_CONCPP_LIBRARIES
    ${MYSQL_CONCPP_ROOT}/lib64/vs14/debug/mysqlcppconn.lib
    ${MYSQL_CONCPP_ROOT}/lib64/vs14//debug/mysqlcppconn8.lib
)

# -------spdlog-------
include_directories("D:/cppsoft/spdlog-1.x/include")
# 必须定义这个宏才能输出文件名和行号还有方法名
add_compile_definitions(SPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_TRACE)

# 过滤掉不需要的文件
list(FILTER SRCS EXCLUDE REGEX "/test\\.cpp")
# list(FILTER SRCS INCLUDE REGEX "/test\\.cpp")
message("values of SRCS: ${SRCS}")
# 指定链接库路径
# find_library(NAMES mysqlcppconn-9-vs14 mysqlcppconn8-2-vs14 PATHS ${LIBS})
# 添加可执行程序
add_executable( ${PROJECT_NAME} ${SRCS})
# 复制第三方库到生成目录
file(COPY ${LIBS} DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/build)

# 链接库
# 链接Boost.Asio库
target_link_libraries( ${PROJECT_NAME} ${Boost_LIBRARIES})

# 链接MySQL库
# target_link_libraries(${PROJECT_NAME} ${MYSQL_CONCPP_LIBRARIES} -lmysqlcppconn-9-vs14 -lmysqlcppconn8-2-vs14)
target_link_libraries(${PROJECT_NAME} ${MYSQL_CONCPP_LIBRARIES})

# 添加winsocket相关依赖，windows下的网络编程都需要添加
# 链接winsocket库
if(WIN32)
  target_link_libraries( ${PROJECT_NAME} wsock32 ws2_32)
endif()